Skip to content

feat(agent): add Conjur JWT authentication client - #821

Open
roeezis wants to merge 4 commits into
jetstack:masterfrom
roeezis:split/04-conjur-client
Open

feat(agent): add Conjur JWT authentication client#821
roeezis wants to merge 4 commits into
jetstack:masterfrom
roeezis:split/04-conjur-client

Conversation

@roeezis

@roeezis roeezis commented Aug 23, 2026

Copy link
Copy Markdown

Summary

Part 4 of the SMS/Conjur JWT authentication series (split out of #817). Stacked on #818, #819, and the service-discovery PR — diff will shrink once those merge.

Exchanges a projected ServiceAccount JWT (via the jwtsource package from #818) for a Conjur access token through the authn-jwt endpoint, and authenticates requests with it as identity.RequestAuthenticator. Nothing wires this in yet — that's the next PR, once both this and the legacy identity client exist side by side.

The identity returned for audit tagging is the token's own sub claim when it can be extracted, falling back to the configured service ID otherwise, so an unusual token shape degrades rather than fails the request.

Test plan

  • go build ./...
  • go test ./internal/cyberark/conjur/...
  • Live end-to-end verified against a real CyberArk tenant: authn-jwt exchange, snapshot-links, and S3 upload all succeed.

@mladen-rusev-cyberark mladen-rusev-cyberark left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shape is right — plugs into the existing RequestAuthenticator seam, fails closed on non-200, and unlike the legacy identity client it refreshes its own token. Main concern is the token lifetime handling (inline).

Two smaller things: New and MockConjurExchangeServerStatus are missing doc comments; and buildJWSToken only emits base64.StdEncoding, so three of the four encodings conjurTokenObject claims to tolerate (raw JSON, URL-safe base64, unpadded) are never exercised — a table test over all four would be cheap.

Comment thread internal/cyberark/conjur/conjur.go Outdated
Comment thread internal/cyberark/conjur/conjur.go Outdated
Comment thread internal/cyberark/conjur/conjur.go
@roeezis
roeezis force-pushed the split/04-conjur-client branch from b29357f to 81d45a9 Compare August 24, 2026 11:42
rzisholz added 2 commits August 24, 2026 14:43
Introduces a small, isolated interface for reading a JWT from a file
path — the first piece of the upcoming Conjur JWT authentication path,
split out on its own since nothing else in this PR depends on it yet.
identity.go mixed the shared client/token-cache plumbing with the
CyberArk Identity username/password (UP) login flow. Move the UP-specific
code into username_password.go so the shared plumbing stays easy to find
once a second login mechanism (Conjur JWT) is added alongside it.

No behavior change — pure extraction, plus exporting the mock's success
credentials for other packages' tests.
@roeezis
roeezis force-pushed the split/04-conjur-client branch from 81d45a9 to b59e43d Compare August 24, 2026 11:45
@roeezis

roeezis commented Aug 24, 2026

Copy link
Copy Markdown
Author

All three addressed:

  • TTL is now driven by the token's own exp claim when it can be read (renamed identityFromToken -> claimsFromToken to also extract it), falling back to a guessed TTL — now a Client field, not a package const — only when the token doesn't parse. Added Invalidate() for callers to force a fresh exchange on a 401, and a comment on the mutex-held-across-round-trip behavior noting it's deliberate. Also added tests: expired exp forces a re-exchange, a future exp overrides a short fallback TTL, and Invalidate forces a re-exchange.
  • Exchange errors on a non-200 now include a bounded prefix of Conjur's own response body, and drain the remainder so the connection can be reused. Added a test asserting the body's message surfaces in the error.

Comment thread internal/cyberark/conjur/conjur.go
rzisholz added 2 commits August 24, 2026 19:34
The Service Discovery API returns several independently-hosted services;
the authn-jwt exchange this PR series adds is served by secrets_manager,
a different host from identity_administration. Add a SecretsManager
field to Services and parse it, so callers have it available — nothing
reads it yet, that lands in a later PR alongside the client that needs
it.

secrets_manager and discoveryContext are deliberately not required here
unlike identity, since not every caller needs them and requiring
secrets_manager would break every existing username/password install on
a tenant not yet onboarded to Conjur — each caller validates what it
needs at its own point of use instead. identity, by contrast, is
required unconditionally: it's present and active for every healthy
tenant, so callers may rely on it without re-checking.

Factor the repeated "find the first active main endpoint" loop into a
mainActiveAPI helper now that there are three near-identical copies.
Exchanges a projected ServiceAccount JWT (via jwtsource) for a Conjur
access token through the authn-jwt endpoint, and authenticates requests
with it as identity.RequestAuthenticator. Nothing wires this in yet —
that's the next PR, once both this and the legacy identity client exist
side by side.

The identity returned for audit tagging is the token's own sub claim
when it can be extracted, falling back to the configured service ID
otherwise. The cache expiry is driven by the token's own exp claim when
present, falling back to a guessed TTL only when it isn't — a fixed TTL
stamped after the exchange returns would otherwise serve a token past
its real expiry under latency or clock skew. Exposes Invalidate() so a
caller that gets a 401 from the resource server can force a fresh
exchange instead of waiting out the cache.
@roeezis
roeezis force-pushed the split/04-conjur-client branch from b59e43d to 23492e8 Compare August 24, 2026 16:38
@roeezis

roeezis commented Aug 24, 2026

Copy link
Copy Markdown
Author

Took the suggested comment as-is — accurately scopes the current guarantee without overclaiming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants